<template>
  <div class="content-wrapper">
    <!-- <div class="content-header"></div> -->
    <!-- <div class="title">
      <div>台账文件</div>
    </div>
    <el-divider></el-divider> -->
    <div class="content-container">
      <div class="filter-container"></div>
      <div>
        <!-- <div v-if="multipleSelection.length > 0" class="filter-container">
          <span class="filter-item filter-item-label">批量操作 </span>
          <el-button size="mini" round class="filter-item" @click="batchRecover"
            >恢复<i
              class="el-icon-refresh-right el-icon--right button-icon blove-color"
          /></el-button>
          <el-button type="danger" plain size="mini" round class="filter-item" @click="batchDelete"
            >永久删除<i
              class="el-icon-refresh-right el-icon--right button-icon el-icon-delete"
          /></el-button>
        </div> -->
        <el-table
          height="800"
          v-loading="listLoading"
          :data="list"
          highlight-current-row
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" width="55" fixed></el-table-column> -->
          <el-table-column label="名称" prop="folderName" min-width="200">
            <template slot-scope="scope">
              <svg class="icon" aria-hidden="true">
                <use
                  :xlink:href="iconType(scope.row.fileExtension).class"
                ></use>
              </svg>
              <span v-if="scope.row.folderName">{{
                scope.row.folderName
              }}</span>
              <span v-if="scope.row.documentName"
                >{{ scope.row.documentName }}{{ scope.row.fileExtension }}</span
              >
            </template>
          </el-table-column>
          <!-- <el-table-column label="删除人" prop="createdName" width="150px" /> -->
          <el-table-column
            label="最近使用时间"
            prop="accessTimeString"
            align="center"
            :show-overflow-tooltip="true"
          />
          <!-- <el-table-column
            label="大小"
            prop="size"
            width="160px"
            align="center"
          /> -->
          <el-table-column label="大小" prop="size" width="100px" />
          <el-table-column
            label="操作"
            align="center"
            width="150px"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-dropdown trigger="click" class="filter-item">
                <el-button type="text"><i class="el-icon-more"></i></el-button>
                <el-dropdown-menu slot="dropdown" class="user-dropdown">
                  <el-dropdown-item
                    v-if="scope.row.documentId"
                    @click.native="openDocument(scope.row)"
                    >预览</el-dropdown-item
                  >
                  <el-dropdown-item
                    v-if="scope.row.documentId"
                    @click.native="deleteDocument(scope.row)"
                    >删除</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getLedger } from '@/api/fd/folder'
import { deleteDocument } from '@/api/fd/document.js'

import { unity } from '@/styles/js/setIconType.js'
export default {
  components: { File },
  data() {
    return {
      iconType: unity.setIconType,
      multipleSelection: [],
      list: null,
      total: 0,
      listLoading: true,
      deleteData: {
        folderIds: [],
        documentIds: []
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val
      console.log(this.multipleSelection, 'this.multipleSelection')
    },
    getList() {
      getLedger({}).then((res) => {
        this.list = res.data
        this.listLoading = false
      })
    },

    //预览
    openDocument(row) {
      var mode = row.accessType == 0 ? 'view' : 'edit'
      window.open(
        'onlyoffice/createDocument.html?&token=' +
          this.$store.getters.token +
          '&documentId=' +
          row.documentId +
          '&mode=' +
          mode +
          '&urldata=' +
          process.env.VUE_APP_BASE_API
      )
    },
    deleteDocument(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteDocument({ documentId: row.documentId }).then((res) => {
            if (res.code === 1) {
              this.$message.success('删除成功')
              this.getList()
            }
          })
        })
        .catch(() => {
          this.$message.info('已取消删除')
        })
    }
  }
}
</script>
